<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- 这个区域被vue控制 -->
        <ul>
            <li v-for="(item,index) in arr">{{item}}
                <button @click="del(index)">删除</button>
            </li>
            <button @click="add">生成</button>
        </ul>
    </div>
    <script src="./vue.js"></script>
    <script>
        new Vue({
            // vue的配置对象
            el: '#app',
            data: {
                arr: [1, 2, 3]
            },
            methods: {
                // 增加
                add() {
                    let random = Math.floor(Math.random() * 21)
                    this.arr.push(random)
                },
                // 删除
                del(index) {
                    this.arr.splice(index, 1)
                }
            }
        })
    </script>
</body>

</html>